<template>
  <div class="room-log">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>系统设置</el-breadcrumb-item>
      <el-breadcrumb-item>
        <a>数据统计</a>
      </el-breadcrumb-item>
    </el-breadcrumb>
    <div class="easy-content">
      <el-form>
        <el-form-item style="margin-bottom:0;">
          <div class="order-warpper">

            <div class="group-1">
              <el-cascader :options="deptList"
                :props="{ value: 'id', label: 'department', children: 'adminDepartments' }"
                v-model="dept"
                :show-all-levels="false"
                placeholder="请选择部门"
                clearable
                 change-on-select
                @change="setDeptId">
              </el-cascader>
            </div>

            <el-dropdown @command="setTime"
              style="margin-right:15px">
              <span class="el-dropdown-link">
                {{timeTitle}}
                <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item :command="{ 'key' : 'time', value: '', title: '全部时间' }">全部时间</el-dropdown-item>
                <el-dropdown-item :command="{ 'key' : 'time', value: '1', title: '操作时间' }">操作时间</el-dropdown-item>
                <el-dropdown-item :command="{ 'key' : 'time', value: '2', title: '完成时间' }">完成时间</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <el-date-picker type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="setInOutTime"
              v-model="startEndTime"
              :disabled="cancelTime">
            </el-date-picker>
            <div class="group-1"
              style="margin-left:15px;">
              <el-input placeholder="请输入员工账号/姓名"
                v-model="search"
                clearable>
              </el-input>
            </div>
            <el-button type="primary"
              @click.native="_search"
              class="searc"
              style=" line-height: 32px;padding: 0 21px;">
              <i class="el-icon-search"></i>
            </el-button>
          </div>
          <el-form-item>
            <el-button type="primary"
              class="searc"
              size="small"
              style="margin-top:20px;"
              @click.native="_exportStatisticsList"
              v-has="'logroomstatisticsoutputlist'"
              :disabled="!roomStatisticsList.length">
              导出日志
            </el-button>
          </el-form-item>
        </el-form-item>
        <el-form-item class="easy-table">
          <el-table :data="roomStatisticsList"
            style="width: 100%"
            max-height="600"
            @sort-change="sortHandle"
            :summary-method="getSummaries"
            show-summary>
            <el-table-column prop="account"
              label="操作账号"
              min-width="100">
            </el-table-column>
            <el-table-column prop="name"
              label="操作姓名"
              min-width="100">
            </el-table-column>
            <el-table-column prop="dept"
              label="部门"
              min-width="100">
            </el-table-column>
            <el-table-column prop="radioRoom"
              label="完成报房"
              min-width="100"
              sortable>
            </el-table-column>
            <el-table-column prop="sweep"
              label="打扫完成"
              min-width="100"
              sortable>
            </el-table-column>
            <el-table-column prop="waive"
              label="放弃打扫"
              min-width="100"
              sortable>
            </el-table-column>
            <el-table-column prop="anew"
              label="重扫完成"
              min-width="100"
              sortable>
            </el-table-column>
            <el-table-column prop="win"
              label="核房通过"
              min-width="100"
              sortable>
            </el-table-column>
            <el-table-column prop="loser"
              label="核房不通过"
              min-width="100"
              sortable>
            </el-table-column>
          </el-table>
        </el-form-item>
        <el-form-item>
          <el-pagination @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNo"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="total, prev , pager , next, sizes"
            :total="total"
            style="margin-top:20px">
          </el-pagination>
        </el-form-item>
      </el-form>

    </div>
  </div>
</template>
<script>
import { roomLogList } from "@/public/js/log";
import { getDeptstaffAll } from "@/public/js/setting";
import { roomStatisticsList, getRoomStatisticsExport } from "@/public/js/count";
import { exportToExcel } from "@/public/js/util";
export default {
  data() {
    return {
      roomStatisticsList: [],
      deptId: "",
      startEndTime: [],
      deptList: [],
      dept: [],
      moduleId: "",
      time: "",
      pageNo: 1,
      pageSize: 10,
      search: "",
      total: 0,
      props: {
        value: "id",
        children: "children",
        label: "label"
      },
      timeTitle: "全部时间",
      cancelTime: true,
      startTime: "",
      endTime: "",
      exportList: [],
      sortby: "",
      sort: "",
      sum: ""
    };
  },
  created() {
    this.getDepList();
    this._roomStatisticsList();
  },

  mounted() {},
  methods: {
    sortHandle(data) {
      this.sortby = data.prop;
      this.sort = data.order;
      this.pageNo = 1;
      this._roomStatisticsList();
    },

    getSummaries(param) {
      const { columns } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) sums[index] = "总合计";
        if (index === 3) sums[index] = "完成报房: " + this.sum.radioRoom;
        if (index === 4) sums[index] = "打扫卫生: " + this.sum.sweep;
        if (index === 5) sums[index] = "放弃打扫: " + this.sum.waive;
        if (index === 6) sums[index] = "重扫完成：" + this.sum.anew;
        if (index === 7) sums[index] = "核房完成：" + this.sum.win;
        if (index === 8) sums[index] = "核房不通过：" + this.sum.loser;
      });
      return sums;
    },
    // 获取部门列表数据
    getDepList() {
      getDeptstaffAll().then(res => {
        if (res.data.errCode === 0) this.deptList = res.data.adminDepartments;
      });
    },
    _search(){
      this.pageNo =1;
      this._roomStatisticsList();
    },
    // 获取统计
    _roomStatisticsList() {
      roomStatisticsList({
        pageSize: this.pageSize,
        pageNum: this.pageNo,
        search: this.search,
        deptId: this.deptId,
        time: this.time,
        startTime: this.startTime,
        endTime: this.endTime,
        sortby: this.sortby,
        sort: this.sort
      }).then(res => {
       
        this.roomStatisticsList = res.data.roomStatisticsList;
        this.total = res.data.total;
        this.sum = res.data.sum;
      });
    },
    // 设置时间查询类型
    setTime(data) {
      this.timeTitle = data.title;
      this.time = data.value;
      if (this.time !== "") {
        this.cancelTime = false;
        this.startEndTime = [];
      } else {
        this.cancelTime = true;
        this.startEndTime = [];
        this.pageNo = 1;
        this._roomStatisticsList();
      }
    },
    // 时间查询
    setInOutTime(data) {
      if (data) {
        this.startTime = data[0];
        this.endTime = data[1];
      } else {
        this.startTime = "";
        this.endTime = "";
      }
      this.pageNo =1;
      this._roomStatisticsList();
    },
    // 获取导出列表数据
    _getRoomStatisticsExport(callBack) {
      getRoomStatisticsExport({
        pageSize: this.pageSize,
        pageNum: this.pageNo,
        search: this.search,
        deptId: this.deptId,
        time: this.time,
        startTime: this.startTime,
        endTime: this.endTime
      }).then(res => {
        this.exportList = res.data.roomStatisticsList;
        callBack();
      });
    },
    // 设置部门
    setDeptId() {
      this.deptId = this.dept[this.dept.length - 1];
      this.pageNo =1;
      this._roomStatisticsList();
    },
    // 分页
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this._roomStatisticsList();
    },
    handleCurrentChange(pageNo) {
      this.pageNo = pageNo;
      this._roomStatisticsList();
    },
    _exportStatisticsList() {
      this._getRoomStatisticsExport(() => {
        const tHeader = [
          "操作账号",
          "操作姓名",
          "部门",
          "完成报房",
          "打扫完成",
          "放弃打扫",
          "重扫完成",
          "核房通过",
          "核房不通过"
        ];
        const filterVal = [
          "account",
          "name",
          "dept",
          "radioRoom",
          "sweep",
          "waive",
          "anew",
          "win",
          "loser"
        ];
        exportToExcel(tHeader, filterVal, this.exportList, "房务统计表");
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.order-warpper {
  .group-1 {
    width: 180px;
    display: inline-block;
    margin-right: 20px;
    .el-cascader,
    .el-select {
      width: 100%;
    }
  }
  .group-2 {
    width: 280px;
    display: inline-block;
    margin-right: 20px;
    .el-date-editor {
      width: 100%;
      padding: 0 10px;
    }
  }
  .group-3 {
    margin-top: 20px;
  }
  .btn {
    text-align: right;
  }
  .el-input__inner {
    height: 34px;
  }
  .search-button .el-button {
    padding: 9px 20px;
  }
}

.account-content {
  & > div {
    display: flex;
    padding-bottom: 15px;
    & > div {
      flex: 1;
    }
  }
}
.miNiCommListTable {
  border: 1px solid #ddd;
  border-right: 0;
  li {
    display: flex;
    border-bottom: 1px solid #ddd;

    div {
      flex: 1;
      line-height: 45px;
      font-size: 12px;
      text-indent: 23px;
      border-right: 1px solid #ddd;
    }
    &.header > div {
      background: #eef1f9;
      color: #415161;
    }
    & > .input-number .input-number-count {
      text-align: center;
      text-indent: 0;

      p {
        display: inline-block;
        background: #6d2377;
        height: 30px;
        line-height: 30px;
        width: 30px;
        border-radius: 5px 0 0 5px;
        color: #fff;
        cursor: pointer;
      }
      input {
        display: inline-block;
        height: 30px;
        line-height: 30px;
        border: none;
        width: 30px;
        text-align: center;
        border: 1px solid #6d2377;
        box-sizing: border-box;
      }
    }
  }
}
.handleBtn {
  float: left;
  height: 47px;
  line-height: 47px;
  padding-left: 15px;
  color: #409eff;
}
.inline-block {
  display: flex;
  & > div.el-form-item {
    flex: 1;
  }
}
.el-range-editor {
  width: 250px;
}
</style>


